<template>
  <div :style="bill.CSB_Status == -100 ? 'color: red' : ''" style="display: flex">
    <div style="width: 185px">
      <el-image style="height: 110px; width: 165px" fit="fill" v-if="bill.FL_SrcPath" :src="fileURL + bill.FL_SrcPath"
        :preview-src-list="[fileURL + bill.FL_SrcPath]"></el-image>
      <el-tag style="margin: 12px 0" :type="tagType">
        {{ bill.StatusDesc }}
      </el-tag>
    </div>

    <div style="
        display: flex;
        flex-direction: column;
        justify-content: space-around;
      ">
      <div class="item">
        <div class="item-title">编号</div>
        <el-popover placement="top-start" trigger="hover">
          <p>ID:{{ bill.CSB_ID }}</p>
          <p>发票号码:{{ bill.CSB_No }}</p>
          <div class="item-content" slot="reference" v-if="bill.CSB_No">
            {{ bill.CSB_No.substring(0, 8) + '...' }}
          </div>
        </el-popover>
      </div>

      <div class="item">
        <div class="item-title">票税合计</div>
        <div class="item-content">{{ bill.CSB_Fee }}元</div>
      </div>
      <div class="item">
        <div class="item-title">税额</div>
        <div class="item-content">{{ bill.CSB_TaxFee }}元</div>
      </div>
      <div class="item">
        <div class="item-title">金额</div>
        <div class="item-content">{{ bill.CSB_WithOutTaxFee }}元</div>
      </div>

      <div class="item">
        <div class="item-title">开票日期</div>
        <div class="item-content">{{ bill.CSB_BillDate | formatDate }}</div>
      </div>
      <div class="item" v-if="bill.CSB_RefundTime">
        <div class="item-title">退票日期</div>
        <div class="item-content">
          {{ bill.CSB_RefundTime | formatDate }}
        </div>
      </div>
      <div v-if="bill.CSB_RefundTime">
        <el-popover placement="top-start" trigger="hover">
          <p>退票原因:{{ bill.CSB_RefundReason }}</p>
          <div class="item" slot="reference">
            <div class="item-title">退票日期</div>
            <div class="item-content">
              {{ bill.CSB_RefundTime | formatDate }}
            </div>
          </div>
        </el-popover>
      </div>

      <div class="item">
        <div class="item-title">机构回款</div>
        <div class="item-content">
          {{ bill.ReturnSum1 }}元
          <!-- <el-popover placement="top-start" title="平台回款记录" trigger="hover">
            <div v-for="r in bill.Returns" :key="r.CSBR_ID" style="margin-bottom: 5px">
              {{ r.CSBR_AccountTime | formatDate }} :{{ r.CSBR_Fee }}元

              <el-button type="text" size="mini" @click="deleteBillReturn(r)">
                删除
              </el-button>
            </div>
            <i v-if="bill.Returns.length" slot="reference" class="el-icon-document"
              style="color: #1890ff; cursor: pointer"></i>
          </el-popover> -->
        </div>
      </div>
      <div class="item">
        <div class="item-title">平台回款</div>
        <div class="item-content">
          {{ bill.ReturnSum }}元
          <!-- <el-popover placement="top-start" title="平台回款记录" trigger="hover">
            <div v-for="r in bill.Returns" :key="r.CSBR_ID" style="margin-bottom: 5px">
              {{ r.CSBR_AccountTime | formatDate }} :{{ r.CSBR_Fee }}元

              <el-button type="text" size="mini" @click="deleteBillReturn(r)">
                删除
              </el-button>
            </div>
            <i v-if="bill.Returns.length" slot="reference" class="el-icon-document"
              style="color: #1890ff; cursor: pointer"></i>
          </el-popover> -->
        </div>
      </div>
      <div v-if="bill.CSB_Remark">备注：{{ bill.CSB_Remark }}</div>
    </div>
  </div>
</template>
<script>
import { baseURL, fileRoot } from '@/config'
import { deleteBillReturn } from '@/api/core/caseBillApply'
export default {
  props: ['bill'],
  computed: {
    tagType() {
      return this.bill.StatusDesc == '已开票' ? 'success' : 'danger'
    },
  },
  data: function () {
    return {
      fileURL: baseURL + fileRoot,
    }
  },
  methods: {
    deleteBillReturn(item) {
      this.$confirm(`是否删除该回款记录？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        deleteBillReturn(item.CSBR_ID).then(() => {
          this.$emit('deleteReturn', item)
        })
      })
    },
  },
}
</script>
<style scoped>
.item {
  display: flex;
  align-items: center;
}

.item-title {
  width: 65px;
  height: 18px;
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  font-size: 13px;
  color: #666666;
  line-height: 18px;
  text-align: justify;
  font-style: normal;
  box-sizing: border-box;
  flex: none;
}

.item-title::after {
  display: inline-block;
  width: 100%;
  content: '';
}

.item-content {
  margin-left: 8px;
}
</style>